// pages/submit/components/SelectBox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    shippingMethods: {
      type: Array,
    },
    shippingMethod:{
      type:Number
    }
  },
  lifetimes: {
    attached() {
      var _this = this
      _this.data.distribution = []
      console.log(this.data.shippingMethods)
      _this.data.shippingMethods.forEach(function(item){
        if(item == 0){
          var distribution = {
            title: '普通快递',
            status: false,
            id:0
          }
          _this.data.distribution.push(distribution)
        } else if (item == 1){
          var distribution = {
            title: '到店提货',
            status: false,
            id:1
          }
          _this.data.distribution.push(distribution)
        }else if (item == 2){
          var distribution = {
            title: '同城配送',
            status: false,
            id:2
          }
          _this.data.distribution.push(distribution)
        }
      })
      _this.data.distribution.forEach(function(item){
        if (item.id == _this.data.shippingMethod){
          item.status = true
        }
      })
      _this.setData({
        distribution: _this.data.distribution
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    distribution: [],
    index:0
  },

  /**
   * 组件的方法列表
   */
  attached(){
    var _this = this
    _this.data.distribution[0].status = true
    _this.setData({
      distribution: _this.data.distribution
    })
  },
  methods: {
    chooseClick(data) {
      var _this = this
      _this.data.distribution.forEach(function(item) {
        item.status = false
      })
      _this.data.distribution[data.currentTarget.dataset.index].status = !_this.data.distribution[data.currentTarget.dataset.index].status
      _this.data.index = data.currentTarget.dataset.index
      _this.setData({
        distribution: _this.data.distribution,
        index: _this.data.index
      })
    },
    completeClick(){
      var completeDelivery = { completeDelivery: this.data.distribution[this.data.index]};
      this.triggerEvent("completeDelivery", completeDelivery)
    },
    cencleClick(){
      var cencleDelivery = { cencleDelivery: false };
      this.triggerEvent("cencleDelivery", cencleDelivery)
    }
  }
})